package com.coolbi.onsupai.core.biz.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.biz.SmsBiz;
import com.coolbi.onsupai.core.dao.SmsDao;
import com.coolbi.onsupai.core.entity.Sms;
import com.coolbi.onsupai.core.exception.ServiceException;
import com.coolbi.onsupai.core.exception.SystemException;

public class SmsBizImpl implements SmsBiz {

	@Autowired
	private SmsDao smsDao;
	
	@Override
	public Sms save(Sms obj) {
		try {
			smsDao.save(obj);
			if (null == obj.getId()) {
				throw new ServiceException("发生短消息失败！");
			}
		} catch (Exception e) {
			throw new SystemException("发送短消息发生错误！", e);
		}
		return obj;
	}

	@Override
	public void delete(long id) {
		try {
			if (smsDao.delete(id) < 1) {
				throw new ServiceException("删除短消息失败");
			}
		} catch (Exception e) {
			throw new SystemException("删除短消息发生错误！", e);
		}
	}

	@Override
	public void update(Sms obj) {
		try {
			if (smsDao.update(obj) < 1) {
				throw new ServiceException("更新短消息失败！");
			}
		} catch (Exception e) {
			throw new SystemException("更新短消息发生错误！", e);
		}
	}

	@Override
	public Sms get(long id) {
		return smsDao.get(id);
	}

	@Override
	public List<Sms> list() {
		return smsDao.list();
	}

	@Override
	public List<Sms> listByPage(int offset, int limit) {
		return smsDao.listByPage(offset, limit);
	}

	@Override
	public List<Sms> find(Map<String, Object> parameter) {
		return smsDao.find(parameter);
	}

	@Override
	public List<Sms> findByPage(Map<String, Object> parameter, int offset,
			int limit) {
		return smsDao.findByPage(parameter, offset, limit);
	}

	@Override
	public List<Sms> search(Map<String, Object> parameter, int offset, int limit) {
		return smsDao.search(parameter, offset, limit);
	}

	@Override
	public int count() {
		return smsDao.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return smsDao.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return smsDao.count(parameter);
	}

	public void setSmsDao(SmsDao smsDao) {
		this.smsDao = smsDao;
	}

	@Override
	public List<Sms> findByPage(Long id, Boolean isReaded, Integer smsType,
			int offset, int limit) {
		return smsDao.findByPage(id, isReaded, smsType, offset, limit);
	}

	@Override
	public int count(Long id, Boolean isReaded, Integer smsType) {
		return smsDao.count(id, isReaded, smsType);
	}

	@Override
	public List<Sms> findByPage(Long id, int offset, int limit) {
		return smsDao.findByPage(id, offset, limit);
	}

	@Override
	public int count(Long id) {
		return smsDao.count(id);
	}

	@Override
	public void updateReadStatus(Long id, Boolean isReaded) {
		try {
			if (smsDao.updateReadStatus(id, isReaded) < 1) {
				throw new ServiceException("修改阅读状态失败！");
			}
		} catch (Exception e) {
			throw new SystemException("修改阅读状态发生错误！");
		}
	}

}
